package com.bestom.videoplay;

import android.app.Application;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.IBinder;

import com.bestom.videoplay.callback.BTGattCallback;

import com.bestom.videoplay.service.VideoPlayService;

import static android.bluetooth.BluetoothDevice.TRANSPORT_LE;

public class MediaApplication extends Application {

    private MediaPlayer mediaPlayer;
    private BluetoothGatt mBluetoothGatt;
    private BluetoothAdapter mBluetoothAdapter;
    private BluetoothDevice mBluetoothDevice;
    private VideoPlayService.MediaControlBinder mIBinder;
    public static MediaApplication application;

    @Override
    public void onCreate() {
        super.onCreate();
        application = this;

    }

    public static MediaApplication getApplication(){
        return application;
    }

    public MediaPlayer getMediaPlayer() {
        return mediaPlayer;
    }

    public void setMediaPlayer(MediaPlayer mediaPlayer) {
        this.mediaPlayer = mediaPlayer;
    }

    public BluetoothGatt getmBluetoothGatt() {
        return mBluetoothGatt;
    }

    public void setmBluetoothGatt(BluetoothGatt mBluetoothGatt) {
        this.mBluetoothGatt = mBluetoothGatt;
    }

    public BluetoothAdapter getmBluetoothAdapter() {
        return mBluetoothAdapter;
    }

    public void setmBluetoothAdapter(BluetoothAdapter mBluetoothAdapter) {
        this.mBluetoothAdapter = mBluetoothAdapter;
    }

    public BluetoothDevice getmBluetoothDevice() {
        return mBluetoothDevice;
    }

    public void setmBluetoothDevice(BluetoothDevice mBluetoothDevice) {
        this.mBluetoothDevice = mBluetoothDevice;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
            mBluetoothGatt = mBluetoothDevice.connectGatt(getApplicationContext(),true, new BTGattCallback(), TRANSPORT_LE);
        }else {
            mBluetoothGatt = mBluetoothDevice.connectGatt(getApplicationContext(),true,new BTGattCallback());
        }
        setmBluetoothGatt(mBluetoothGatt);
    }

    public VideoPlayService.MediaControlBinder getmIBinder() {
        return mIBinder;
    }

    public void setmIBinder(VideoPlayService.MediaControlBinder mIBinder) {
        this.mIBinder = mIBinder;
    }
}
